package com.mz.demo.controller;

import com.mz.demo.entity.SysPermission;
import com.mz.demo.entity.vo.PermissionVo;
import com.mz.demo.service.PermissionService;
import com.mz.demo.utils.entity.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    /**
     * 1、增加权限
     * */
    @PostMapping
    public R addPermission( @RequestBody PermissionVo permissionVo ){

        permissionService.addPermission(permissionVo);
        return R.ok();
    }


    /**
     * 2、获取权限列表
     * */
    @GetMapping("/tree")
    public R getPermissionTree(){

        List<SysPermission> sysPermissionList =  permissionService.getPermissionTree();
        return R.ok(sysPermissionList);
    }


    /**
     * 3、修改权限
     * */
    @PutMapping
    public R updatePermissionInfo(@RequestBody PermissionVo permissionVo){

        permissionService.updatePermissionInfo(permissionVo);
        return R.ok();
    }


    /**
     * 4、删除权限
     * */
    @DeleteMapping
    public R removePermission( Long permissionId ){

        permissionService.removePermission(permissionId);
        return R.ok();
    }
}
